#include "Options.h"
#include "ui_Options.h"
#include <QFontDialog>
#include "CCatSettings.h"
Options::Options(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Options)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(onFont()));
    CCatSettings::unserialize("setting.ini");
    QVariant v= CCatSettings::value("editor.font");
    if(v.isValid())
    {
        _currentFont=v.value<QFont>();
    }
    updateFontInfo();
}

Options::~Options()
{
    delete ui;
}

void Options::onFont()
{
    bool ok;
    _currentFont=QFontDialog::getFont(&ok,_currentFont);
    updateFontInfo();
    QVariant v;v.setValue<QFont>(_currentFont);
    CCatSettings::setValue("editor.font",v);
    CCatSettings::serialize("setting.ini");
    emit sFontChange();
}

void Options::updateFontInfo()
{
    QString info=QString("%1").arg(_currentFont.family());
    ui->labelFont->setText(info);
}
